using System;
using Microsoft.SPOT;

namespace Gadgeteer.Interfaces.Timed
{
    public abstract class TimerFactoryBase
    {
       public abstract ITimer Create(TimeSpan dueIn, TimeSpan interval, TimerBehavior behavior);

        private const TimerBehavior defaultBehaviour = TimerBehavior.RunContinuously;

        protected static TimeSpan TimeSpanFromMilliseconds(int miliseconds)
        {
            return new TimeSpan(0, 0, 0, 0, miliseconds);
        }

        public ITimer Create(int dueIn, int intervalMiliseconds, TimerBehavior behavior)
        {
            return Create(
                TimeSpanFromMilliseconds(dueIn),
                TimeSpanFromMilliseconds(intervalMiliseconds),
                behavior);
        }

        public ITimer Create(int intervalMiliseconds, TimerBehavior behavior)
        {
            return Create(
                TimeSpanFromMilliseconds(intervalMiliseconds),
                TimeSpanFromMilliseconds(intervalMiliseconds),
                behavior);
        }

        public ITimer Create(TimeSpan interval, TimerBehavior behavior)
        {
            return Create(
                TimeSpanFromMilliseconds(0),
                interval,
                behavior);
        }

        public ITimer Create(int intervalMiliseconds)
        {
            return Create(
                TimeSpanFromMilliseconds(intervalMiliseconds),
                TimeSpanFromMilliseconds(intervalMiliseconds),
                defaultBehaviour);
        }

        public ITimer Create(TimeSpan interval)
        {
            return Create(
                TimeSpanFromMilliseconds(0),
                interval,
                defaultBehaviour);
        }
    }
}
